USE ratel;

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;


/*==============================================================*/
/* Table: t_dict_type                                           */
/*==============================================================*/
drop table if exists t_dict_type;
create table t_dict_type
(
   id                   bigint(20) unsigned NOT NULL AUTO_INCREMENT,
   dict_type            varchar(16) not null comment '字典类型',
   dict_name            varchar(64) comment '字典名',
   dict_desc            varchar(255) comment '字典描述',
   use_flag             char(1) default 'N' comment 'Y正常 N停用',
   created_by           varchar(64),
   created_time         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   updated_by           varchar(64),
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   ori_id               varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128),
   primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='字典类型';
create unique index idx_dict_type_dt on t_dict_type
(
   dict_type
);


-- ----------------------------
-- Records of t_dict_type
-- ----------------------------
BEGIN;
INSERT INTO `t_dict_type` VALUES (1, 'dict_type', '字典类型', '系统类不能修改', 'Y', NULL, '2019-05-16 14:16:20', NULL, '2019-05-16 14:20:16', NULL, 1, NULL);
INSERT INTO `t_dict_type` VALUES (2, 'status_type', '租户状态', '租户状态字典', 'Y', NULL, '2019-05-16 14:16:20', NULL, '2019-05-16 14:20:16', NULL, 1, NULL);
INSERT INTO `t_dict_type` VALUES (3, 'param_type', '参数类型', '参数类型字典', 'Y', NULL, '2019-05-16 14:16:20', NULL, '2019-05-16 14:20:16', NULL, 1, NULL);
COMMIT;

/*==============================================================*/
/* Table: t_dict_code                                           */
/*==============================================================*/
drop table if exists t_dict_code;
create table t_dict_code
(
   id                   bigint(20) unsigned NOT NULL AUTO_INCREMENT,
   dict_type            varchar(32) not null comment '字典类型',
   priority             smallint DEFAULT '0' comment '优先级',
   dict_label           varchar(128) not null comment '字典标签',
   dict_value           varchar(255) not null comment '字典标签值',
   dict_desc            varchar(255) comment '字典描述',
   main_flag            char(1) default 'N' comment '是否默认（Y是 N否）',
   use_flag             char(1) default 'N' comment '（Y正常 N停用）',
   created_by           varchar(64),
   created_time         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   updated_by           varchar(64),
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   ori_id               varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128)  comment '1-系统内置 0-业务类',
   primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='字典明细';
create index idx_dict_code_type on t_dict_code
(
   dict_type
);
create unique index idx_dict_code_lable on t_dict_code
(
   dict_label
);

-- ----------------------------
-- Records of t_dict_code
-- ----------------------------
BEGIN;
INSERT INTO `t_dict_code` VALUES (1, 'dict_type', 0, '系统类', '1', '系统类字典', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (2, 'dict_type', 0, '业务类', '0', '业务类字典', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (3, 'status_type', 0, '正常', '0', '状态正常', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (4, 'status_type', 1, '冻结', '9', '状态冻结', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (5, 'param_type', 0, '检索', '1', '检索', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (6, 'param_type', 0, '原文', '2', '原文', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (7, 'param_type', 0, '报表', '3', '报表', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (8, 'param_type', 0, '安全', '4', '安全', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (9, 'param_type', 0, '文档', '5', '文档', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (10, 'param_type', 0, '消息', '6', '消息', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (11, 'param_type', 0, '其他', '9', '其他', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
INSERT INTO `t_dict_code` VALUES (12, 'param_type', 0, '默认', '0', '默认', NULL, 'Y', NULL, '2019-05-16 14:20:40', NULL, '2019-05-16 14:20:40', NULL, 1, NULL);
COMMIT;



/*==============================================================*/
/* Table: shedlock                                              */
/*==============================================================*/
drop table if exists shedlock;
CREATE TABLE shedlock(name VARCHAR(64) NOT NULL, lock_until TIMESTAMP(3) NOT NULL,
    locked_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    locked_by VARCHAR(255) NOT NULL,
    PRIMARY KEY (name)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='任务调度配置';



/*==============================================================*/
/* Table: t_txncode                                             */
/*==============================================================*/
drop table if exists t_txncode;
create table t_txncode
(
   id                   bigint(20) unsigned not null AUTO_INCREMENT,
   txn_code             varchar(32) not null,
   txn_type             varchar(8) comment '11-支付
            参考聚合支付接口规范',
   txn_desc             varchar(1024),
   circuit_type         varchar(8) comment 'SYNC-同步
            ASYNC-异步',
   use_flag             char(1)  default 'Y' comment 'Y-启用
            N-关闭',
   start_date           date,
   expiry_date          date,
   created_by           varchar(64),
   created_time         datetime not null default CURRENT_TIMESTAMP,
   updated_by           varchar(64),
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   ori_id               varchar(32),
   tenant_id            varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128),
   primary key (id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

create unique index idx_txncode_tc on t_txncode
(
   txn_code
);


/*==============================================================*/
/* Table: t_txncode_org_clazz                                   */
/*==============================================================*/
drop table if exists t_txncode_org_clazz;
create table t_txncode_org_clazz
(
   id                   bigint(20) unsigned not null AUTO_INCREMENT,
   txn_code             varchar(32) not null,
   org_code             varchar(16) not null,
   clazz_code           varchar(64) not null,
   clazz_name           varchar(128),
   clazz_desc           varchar(1024),
   clazz_path           varchar(512),
   use_flag             char(1) default 'Y' comment 'Y-启用
            N-关闭',
   remark               varchar(255),
   created_by           varchar(64),
   created_time         datetime not null default CURRENT_TIMESTAMP,
   updated_by           varchar(64),
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   ori_id               varchar(32),
   tenant_id            varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128),
   primary key (id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

create unique index idx_txncode_orgclazz_cotc on t_txncode_org_clazz
(
   clazz_code,
   org_code,
   txn_code
);
create index idx_txncode_orgclazz_ct on t_txncode_org_clazz
(
   created_time
);


/*==============================================================*/
/* Table: t_partner_org_route                                   */
/*==============================================================*/
drop table if exists t_partner_org_route;
create table t_partner_org_route
(
   id                   bigint(20) unsigned not null AUTO_INCREMENT,
   partner_no           varchar(16) not null,
   org_code             varchar(16) not null,
   weight               tinyint(2) unsigned not null,
   priority             smallint unsigned,
   use_flag             char(1)  default 'Y' comment 'Y-启用
            N-关闭',
   start_date           date,
   expiry_date          date,
   created_by           varchar(64),
   created_time         datetime default CURRENT_TIMESTAMP,
   updated_by           varchar(64),
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   ori_id               varchar(32),
   tenant_id            varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128),
   primary key (id),
   unique key partner_cat_payorg_over_weight_pcpo_u (partner_no, org_code)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

create unique index idx_partner_org_route_pnc on t_partner_org_route
(
   partner_no,
   org_code
);
create index idx_partner_org_route_ct on t_partner_org_route
(
   created_time
);


/*==============================================================*/
/* Table: t_errcode_convert                                     */
/*==============================================================*/
drop table if exists t_errcode_convert;
create table t_errcode_convert
(
   id                   bigint(20) unsigned not null AUTO_INCREMENT,
   org_code             varchar(16) not null,
   org_resp_code        varchar(16) not null,
   org_resp_desc        varchar(255),
   resp_code            varchar(8) not null,
   resp_desc            varchar(255),
   err_flag             char(1) default 'N' comment 'Y-成功标志 N-失败标志',
   use_flag             char(1) default 'Y' comment 'Y-启用  N-关闭',
   created_by           varchar(64),
   created_time         datetime not null default CURRENT_TIMESTAMP,
   updated_by           varchar(64),
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   ori_id               varchar(32),
   tenant_id            varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128),
   primary key (id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

create unique index idx_errcode_convert_orc on t_errcode_convert
(
   org_resp_code,
   org_code,
   resp_code
);
create index idx_errcode_convert_ct on t_errcode_convert
(
   created_time
);


/*==============================================================*/
/* Table: t_partner_info                                        */
/*==============================================================*/
drop table if exists t_partner_info;
create table t_partner_info
(
   id                   bigint(20) unsigned not null AUTO_INCREMENT,
   partner_no           varchar(16) not null,
   partner_name         varchar(64),
   partner_grade        char(2) comment '01-1级 02-2级',
   partner_intro        varchar(255),
   serialization_mode   varchar(8) comment 'XML,JSON',
   use_flag             char(1)  default 'Y' comment 'Y-启用 N-关闭',
   group_code           varchar(16),
   arrive_mode          char(2) comment 'T0-当日 T1-隔日 D0-当日(包含节假日) D1-隔日(包含节假日)',
   clearing_mode        varchar(8) comment 'DIRECT-直清 SECOND-二清',
   share_mode           varchar(8) comment 'PARTNER-以合作者的范围进行统一标准分润  MERCHANT-以合作者下的每个商户不同的标准分润',
   contact_name         varchar(32),
   contact_mobile       varchar(32),
   contact_phone        varchar(32),
   contact_fax          varchar(32),
   contact_email        varchar(128),
   f_linkman_name       varchar(32),
   f_linkman_phone      varchar(32),
   f_linkman_fax        varchar(32),
   f_linkman_email      varchar(128),
   remark               varchar(128),
   start_date           date,
   expiry_date          date,
   created_by           varchar(64),
   created_time         datetime not null default CURRENT_TIMESTAMP,
   audited_time         datetime,
   audited_flag         char(1) comment 'N-未审核Y-已审核U-已修改',
   audited_by           varchar(64),
   updated_by           varchar(64),
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   ori_id               varchar(32),
   tenant_id            varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128),
   primary key (id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

create unique index idx_partner_info_pn on t_partner_info
(
   partner_no
);
create index idx_partner_info_ct on t_partner_info
(
   created_time
);


/*==============================================================*/
/* Table: t_partner_key                                         */
/*==============================================================*/
drop table if exists t_partner_key;
create table t_partner_key
(
   id                   bigint(20) unsigned not null AUTO_INCREMENT,
   partner_no           varchar(16) not null,
   key_algorithm        varchar(8) not null comment 'RSA-RSA非对称算法',
   key_length           int(6),
   partner_publickey    text not null,
   partner_publickey_suffix varchar(8) not null,
   partner_privatekey   text,
   partner_privatekey_suffix varchar(8) not null,
   modulus              varchar(255),
   platform_privatekey  text not null,
   platform_publickey   text not null,
   platform_privatekey_suffix varchar(8) not null,
   platform_publickey_suffix varchar(8) not null,
   keypath_type         varchar(16) not null comment 'RELATIVE-相对路径 ABSOLUTE-绝对路径 DATABASE-数据库存储',
   made_time            datetime,
   use_flag             char(1) default 'Y' comment 'Y-启用 N-关闭',
   start_date           date,
   expiry_date          date,
   created_by           varchar(64),
   created_time         datetime not null default CURRENT_TIMESTAMP,
   updated_by           varchar(64),
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   key_index            varchar(4),
   remark               varchar(255),
   tenant_id            varchar(32),
   reversion            bigint(20) unsigned default 0,
   ori_id               varchar(32),
   rsv1                 varchar(128),
   primary key (id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

create index t_partner_key_ct on t_partner_key
(
   created_time
);
create unique index t_partner_key_pn on t_partner_key
(
   partner_no
);



/*==============================================================*/
/* Table: t_merchant_info                                       */
/*==============================================================*/
drop table if exists t_merchant_info;
create table t_merchant_info
(
   id                   bigint(20) unsigned not null,
   merchant_no          varchar(32) not null comment '合作方入驻的商户号',
   partner_no           varchar(16) not null comment '合作方首先入住聚合支付平台， 聚合支付平台通过其中的一个支付机构入到末端支付机构',
   merchant_name        varchar(64),
   merchant_short_name  varchar(32),
   merchant_type        varchar(8) comment 'REALITY-商户真实的 VIRTUAL-商户虚拟的 PARTNET BRUSH',
   merchant_category    varchar(16) comment 'PERSON-个人 ENTERPRISE-企业',
   merchant_intro       varchar(512),
   merchant_level       varchar(8) comment 'MAIN-总店 BRANCH-分店',
   merchant_grade       char(2) comment '01-普通 02-铜牌 03-银牌 04-金牌',
   merchant_logo        varchar(512),
   merchant_license_no  varchar(32),
   merchant_license_expried date,
   merchant_license_pic varchar(512),
   merchant_tax_no      varchar(32),
   merchant_tax_pic     varchar(512),
   merchant_code        varchar(32) not null,
   merchant_status      varchar(8) not null comment 'NORMAL-正常 FREEZE-冻结 CLOSE-销户 LOCK-锁定 NOENABLE-未激活',
   merchant_address     varchar(512),
   merchant_deal_type   varchar(8),
   district_code        varchar(16),
   city_code            varchar(16),
   province_code        varchar(16),
   zip_code             varchar(16),
   service_phone        varchar(32),
   contact_type         varchar(8),
   contact_name         varchar(32),
   contact_mobile       varchar(32),
   contact_fax          varchar(32),
   contact_email        varchar(128),
   draw_fee             decimal(20,0),
   txn_rate             decimal(20,4),
   f_linkman_name       varchar(32),
   f_linkman_phone      varchar(32),
   f_linkman_fax        varchar(32),
   f_linkman_email      varchar(128),
   remark               varchar(128),
   start_date           date,
   expiry_date          date,
   open_hours           varchar(30),
   license_type         char(2),
   license_end_date     date,
   tax_begin_date       date,
   tax_end_date         date,
   legal_gender         char(1) comment 'M-男性；F-女性；N-未知',
   legal_mobile         varchar(16),
   legal_email          varchar(30),
   legal_job            varchar(30),
   legal_address        varchar(50),
   legal_certificate_no varchar(32),
   legal_certificate_type varchar(16) comment 'ID-身份证
            PASSPORT-护照
            MILITARY-军官证
            SOLDIER-士兵证
            HVPS-回乡证
            TEMPID-临时身份证
            BOOKLET-户口簿
            POLICEID-警官证
            MTPS-台胞证
            LICENSE-营业执照
            OTHER-其他
            APOLICE-武警证
            HMPASS-港澳通行证
            SCARD-学生证
            WCARD-工作证
            BLICENSE-工商执照
            UTILITY-事业单位编码
            HOUSE-房产证
            ORGCODE-组织机构编码
            ',
   legal_certificate_begin_date date,
   legal_certificate_end_date date,
   legal_person_head_pic varchar(512),
   legal_person_name    varchar(32),
   legal_certificate_positive_pic varchar(512),
   legal_certificate_back_pic varchar(512),
   license_pic          varchar(512),
   account_type         varchar(8) comment 'PUBLIC-对公 PRIVATE-对私',
   account_no           varchar(64),
   account_name         varchar(128),
   bank_name            varchar(128),
   bank_card_mobile     varchar(16),
   bank_card_address    varchar(255),
   bank_branch_name     varchar(128),
   bank_branch_no       varchar(32),
   bank_no              varchar(32),
   bank_branch_province varchar(16),
   bank_branch_city     varchar(16),
   bank_cardcert_type   varchar(16) comment 'ID-身份证
            PASSPORT-护照
            MILITARY-军官证
            SOLDIER-士兵证
            HVPS-回乡证
            TEMPID-临时身份证
            BOOKLET-户口簿
            POLICEID-警官证
            MTPS-台胞证
            LICENSE-营业执照
            OTHER-其他
            APOLICE-武警证
            HMPASS-港澳通行证
            SCARD-学生证
            WCARD-工作证
            BLICENSE-工商执照
            UTILITY-事业单位编码
            HOUSE-房产证
            ORGCODE-组织机构编码
            ',
   bank_cardcert_no     varchar(32),
   principal_type       varchar(16) comment 'LEGAL：(法人)；CONTROLLER：(实际控制人)；AGENT：(代理人)；OTHER：(其他)',
   principal_head_pic   varchar(512),
   principal_email      varchar(64),
   principal_mobile     varchar(16),
   principal_cert_type  varchar(16) comment 'ID-身份证
            PASSPORT-护照
            MILITARY-军官证
            SOLDIER-士兵证
            HVPS-回乡证
            TEMPID-临时身份证
            BOOKLET-户口簿
            POLICEID-警官证
            MTPS-台胞证
            LICENSE-营业执照
            OTHER-其他
            APOLICE-武警证
            HMPASS-港澳通行证
            SCARD-学生证
            WCARD-工作证
            BLICENSE-工商执照
            UTILITY-事业单位编码
            HOUSE-房产证
            ORGCODE-组织机构编码
            ',
   principal_cert_no    varchar(32),
   principal_cert_positive_pci varchar(512),
   principal_cert_back_pic varchar(512),
   principal_cert_begin_date date,
   principal_cert_end_date date,
   principal_person     varchar(64),
   principal_gender     char(1) comment 'M-男性；F-女性；N-未知',
   org_cert_code        varchar(50),
   org_cert_pic         varchar(512),
   industry_license_pic varchar(512),
   business_select      varchar(128),
   created_by           varchar(64),
   created_time         datetime not null default CURRENT_TIMESTAMP,
   audited_time         datetime,
   audited_flag         char(1) comment 'N-未审核 Y-已审核 U-已修改',
   audited_by           varchar(64),
   updated_by           varchar(64),
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   archived_time        datetime,
   archived_flag        char(1) comment '1:已删除 0:未删除',
   tenant_id            varchar(32),
   ori_id               varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128),
   primary key (id),
   unique key AK_real_merchant_pnmn_u (merchant_no, partner_no)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

create unique index idx_merchant_mcpn on t_merchant_info
(
   merchant_code,
   partner_no
);
create index idx_merchant_pn on t_merchant_info
(
   partner_no
);
create index idx_merchant_ct on t_merchant_info
(
   created_time
);


/*==============================================================*/
/* Table: t_org_info                                            */
/*==============================================================*/
drop table if exists t_org_info;
create table t_org_info
(
   id                   bigint(20) unsigned not null AUTO_INCREMENT,
   org_code             varchar(16) not null,
   out_org_code         varchar(32) not null comment '与out_partner_code相同',
   org_name             varchar(64),
   org_grade            char(2) comment '01-1级 02-2级',
   org_intro            varchar(512),
   network_protocol     varchar(8) comment 'HTTP HTTPS TCP CXF TUXEDO',
   ip                   varchar(64),
   port                 int(5),
   uri                  varchar(128),
   serialization_mode   varchar(8) comment 'XML,JSON',
   use_flag             char(1) not null default 'Y' comment 'Y-启用 N-关闭',
   org_security_key     text,
   start_date           date,
   expiry_date          date,
   contact_name         varchar(32),
   contact_mobile       varchar(16),
   contact_phone        varchar(16),
   contact_fax          varchar(64),
   f_linkman_name       varchar(32),
   f_linkman_phone      varchar(16),
   f_linkman_fax        varchar(32),
   f_linkman_email      varchar(128),
   contact_email        varchar(128),
   remark               varchar(128),
   created_by           varchar(64),
   created_time         datetime not null default CURRENT_TIMESTAMP,
   audited_time         datetime,
   audited_flag         char(1) comment 'N-未审核 Y-已审核 U-已修改',
   audited_by           varchar(64),
   updated_by           varchar(64),
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   ori_id               varchar(32),
   tenant_id            varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128),
   primary key (id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

create unique index idx_org_info_oc on t_org_info
(
   org_code
);
create index idx_org_info_ooc on t_org_info
(
   out_org_code
);
create index idx_org_info_ct on t_org_info
(
   created_time
);


/*==============================================================*/
/* Table: t_log_txn_pay_record                                  */
/*==============================================================*/
drop table if exists t_log_txn_pay_record;
create table t_log_txn_pay_record
(
   id                   bigint(20) unsigned not null,
   int_cut_date         char(8) not null,
   work_id              bigint(20) unsigned not null comment '此id报文头返回给合作方， 同时发送给支付机构作为流水号，同时在平台内部作为唯一的日志跟踪号，最终作为本表的唯一id标识号。',
   merchant_code        varchar(32),
   org_merchant_code    varchar(32) comment 'plat_merchant_code与相同',
   org_code             varchar(16) comment '内部分配的支付机构号 对应org_partner_no
            ',
   partner_no           varchar(16) not null,
   district_code        varchar(16),
   city_code            varchar(16),
   province_code        varchar(16),
   lbs                  varchar(48),
   os                   varchar(32),
   client_ip            varchar(32),
   imei                 varchar(48),
   device_id            varchar(48),
   mobile               varchar(16),
   trace_id             varchar(32) not null,
   txn_type             varchar(8),
   txn_code             char(6) not null,
   req_time             char(14),
   subject              varchar(128),
   description          varchar(255),
   shop_code            varchar(32),
   goods_tag            varchar(32),
   expire_time          int unsigned,
   qr_code              text,
   pay_scene            varchar(8),
   uuid                 varchar(64),
   auth_code            varchar(128),
   source_id            varchar(64),
   buss_type            varchar(8) comment '刷单交易 SCALP 正常交易 NORMAL',
   dcredit_flag         char(1) comment '(支付机构异步通知)贷：C  借 ：D 其他 ：O',
   total_amt            int unsigned not null,
   buyer_pay_amt        int unsigned,
   favor_amt            int unsigned,
   point                int unsigned,
   call_back_url        varchar(255),
   resp_time            char(14),
   resp_code            char(6),
   resp_msg             varchar(255),
   async_version        varchar(16),
   async_txn_code       varchar(6),
   async_trace_id       varchar(32),
   async_ori_trace_id   varchar(32),
   async_work_id        varchar(32) comment 'trace_id与相同',
   async_resp_code      varchar(6),
   async_resp_msg       varchar(6),
   async_resp_time      char(14),
   step                 char(2) comment '01-受理请求插入流水
                                            02-向支付机构发送请求等待支付机构响应
                                            03-收到支付机构同步响应
                                            04-收到支付机构回调响应
                                            05-返回前端商户同步交易完成
                                            06-返回前端商户回调交易完成
                                            ',
   status               varchar(16) not null comment '
                                                        SUCCESS-交易成功
                                                        FAILED-交易失败
                                                        CREATED-交易已创建
                                                        TIMEOUT-交易超时
                                                        PROCESSING-处理中
                                                        CANCELED-订单已取消
                                                        REFUNDED-订单已退款
                                                        WAITING-等待支付
                                                                ',
   org_acct_date        char(8),
   org_version          varchar(16),
   org_partner_no       varchar(16),
   org_trace_id         varchar(32),
   org_resp_seq_id      varchar(64),
   org_clear_flag       varchar(8),
   org_pay_time         char(14),
   org_req_time         varchar(14),
   org_resp_time        char(14),
   org_resp_flag        varchar(4),
   org_resp_code        varchar(64),
   org_resp_msg         varchar(255),
   org_async_trace_id   varchar(32),
   org_async_ori_trace_id varchar(32),
   org_async_work_id    varchar(32) comment 'trace_id与相同',
   org_async_resp_flag  varchar(4),
   org_async_resp_code  varchar(8),
   org_async_resp_msg   varchar(255),
   org_async_resp_time  char(14),
   org_async_status     char(2),
   created_time         datetime not null default CURRENT_TIMESTAMP,
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   ori_id               varchar(32),
   tenant_id            varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128),
   primary key (id),
   unique key AK_txn_pay_oati_u (org_code, org_async_trace_id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

create unique index idx_txn_pay_pntr on t_log_txn_pay_record
(
   trace_id,
   partner_no
);
create index idx_txn_pay_oti on t_log_txn_pay_record
(
   org_trace_id
);
create unique index idx_txn_pay_wi on t_log_txn_pay_record
(
   work_id
);
create index idx_txn_pay_ati on t_log_txn_pay_record
(
   async_trace_id
);
create index idx_txn_pay_oaoti on t_log_txn_pay_record
(
   org_async_work_id
);
create index idx_txn_pay_mc on t_log_txn_pay_record
(
   merchant_code
);

/*==============================================================*/
/* Table: t_notify_record                                       */
/*==============================================================*/
drop table if exists t_notify_record;
create table t_notify_record
(
   id                   bigint(20) unsigned not null,
   partner_no           varchar(16),
   ori_trace_id         varchar(32),
   ori_work_id          varchar(32),
   txn_code             varchar(32),
   notify_url           varchar(512),
   notify_count         tinyint(3) unsigned default 0,
   max_notify_conut     tinyint(3) unsigned default 5,
   status               varchar(8) comment 'TIMEOUT-超时 PROCESSING-处理中 INIT-初始 SUCCESS-成功 FAILED-失败',
   created_time         datetime not null default CURRENT_TIMESTAMP,
   updated_time         datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   ori_id               varchar(32),
   tenant_id            varchar(32),
   reversion            bigint(20) unsigned default 0,
   rsv1                 varchar(128),
   primary key (id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

create index idx_log_notify_oti on t_notify_record
(
   ori_trace_id
);
create index idx_log_notify_opi on t_notify_record
(
   ori_work_id
);


SET FOREIGN_KEY_CHECKS = 1;